﻿<UserControl
    x:Class="WinRTXamlToolkit.Debugging.Views.PropertiesView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:WinRTXamlToolkit.Debugging.Views"
    xmlns:converters="using:WinRTXamlToolkit.Converters"
    xmlns:propertyEditors="using:WinRTXamlToolkit.Debugging.Views.PropertyEditors"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:wrtxtc="using:WinRTXamlToolkit.Controls"
    xmlns:wrtxtce="using:WinRTXamlToolkit.Controls.Extensions"
    xmlns:wrtxtd="using:WinRTXamlToolkit.Debugging.Controls"
    mc:Ignorable="d"
    d:DesignHeight="300"
    d:DesignWidth="400"
    IsTabStop="False">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary
                    Source="ms-appx:///WinRTXamlToolkit.Debugging/Themes/SharedResources.xaml" />
            </ResourceDictionary.MergedDictionaries>

            <converters:BooleanToDoubleConverter
                x:Key="BooleanToDoubleConverter"
                FalseValue="1"
                TrueValue="0.5" />

            <!--ExpanderCheckBoxStyle-->
            <Style
                x:Key="ExpanderCheckBoxStyle"
                TargetType="CheckBox">
                <Setter
                    Property="Background"
                    Value="Transparent" />
                <Setter
                    Property="Foreground"
                    Value="Black" />
                <!--{StaticResource CheckBoxContentForegroundThemeBrush}-->
                <Setter
                    Property="Padding"
                    Value="0,0,0,0" />
                <Setter
                    Property="HorizontalAlignment"
                    Value="Stretch" />
                <Setter
                    Property="VerticalAlignment"
                    Value="Center" />
                <Setter
                    Property="HorizontalContentAlignment"
                    Value="Left" />
                <Setter
                    Property="VerticalContentAlignment"
                    Value="Top" />
                <Setter
                    Property="FontFamily"
                    Value="{StaticResource ContentControlThemeFontFamily}" />
                <Setter
                    Property="FontSize"
                    Value="11" />
                <Setter
                    Property="FontWeight"
                    Value="Bold" />
                <Setter
                    Property="Template">
                    <Setter.Value>
                        <ControlTemplate
                            TargetType="CheckBox">
                            <Border
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                Background="{TemplateBinding Background}">
                                <VisualStateManager.VisualStateGroups>
                                    <VisualStateGroup
                                        x:Name="CommonStates">
                                        <VisualState
                                            x:Name="Normal" />
                                        <VisualState
                                            x:Name="PointerOver">
                                            <Storyboard>
                                                <ColorAnimation
                                                    Storyboard.TargetName="UncheckedVisual"
                                                    Storyboard.TargetProperty="(Path.Stroke).Color"
                                                    To="#FF1BBBFA"
                                                    Duration="0" />
                                                <ColorAnimation
                                                    Storyboard.TargetName="CheckedVisual"
                                                    Storyboard.TargetProperty="(Path.Fill).Color"
                                                    To="#FF1BBBFA"
                                                    Duration="0" />
                                            </Storyboard>
                                        </VisualState>
                                        <VisualState
                                            x:Name="Pressed">
                                            <Storyboard>
                                                <ColorAnimation
                                                    Storyboard.TargetName="UncheckedVisual"
                                                    Storyboard.TargetProperty="(Path.Stroke).Color"
                                                    To="#FF1BBBFA"
                                                    Duration="0" />
                                                <ColorAnimation
                                                    Storyboard.TargetName="CheckedVisual"
                                                    Storyboard.TargetProperty="(Path.Fill).Color"
                                                    To="#FF1BBBFA"
                                                    Duration="0" />
                                            </Storyboard>
                                        </VisualState>
                                        <VisualState
                                            x:Name="Disabled">
                                            <Storyboard>
                                                <DoubleAnimation
                                                    Storyboard.TargetName="Root"
                                                    Storyboard.TargetProperty="Opacity"
                                                    To=".7"
                                                    Duration="0" />
                                                <DoubleAnimation
                                                    Storyboard.TargetName="ContentPresenter"
                                                    Storyboard.TargetProperty="Opacity"
                                                    To=".7"
                                                    Duration="0" />
                                                <ObjectAnimationUsingKeyFrames
                                                    Storyboard.TargetProperty="Foreground"
                                                    Storyboard.TargetName="ContentPresenter">
                                                    <DiscreteObjectKeyFrame
                                                        KeyTime="0"
                                                        Value="{StaticResource CheckBoxContentDisabledForegroundThemeBrush}" />
                                                </ObjectAnimationUsingKeyFrames>
                                            </Storyboard>
                                        </VisualState>
                                    </VisualStateGroup>
                                    <VisualStateGroup
                                        x:Name="CheckStates">
                                        <VisualState
                                            x:Name="Checked">
                                            <Storyboard>
                                                <DoubleAnimation
                                                    Storyboard.TargetName="UncheckedVisual"
                                                    Storyboard.TargetProperty="Opacity"
                                                    To="0"
                                                    Duration="0" />
                                                <DoubleAnimation
                                                    Storyboard.TargetName="CheckedVisual"
                                                    Storyboard.TargetProperty="Opacity"
                                                    To="1"
                                                    Duration="0" />
                                            </Storyboard>
                                        </VisualState>
                                        <VisualState
                                            x:Name="Unchecked" />
                                        <VisualState
                                            x:Name="Indeterminate">
                                            <Storyboard>
                                            </Storyboard>
                                        </VisualState>
                                    </VisualStateGroup>
                                    <VisualStateGroup
                                        x:Name="FocusStates">
                                        <VisualState
                                            x:Name="Focused">
                                            <Storyboard>
                                                <DoubleAnimation
                                                    Duration="0"
                                                    To="1"
                                                    Storyboard.TargetProperty="Opacity"
                                                    Storyboard.TargetName="FocusVisualWhite" />
                                                <DoubleAnimation
                                                    Duration="0"
                                                    To="1"
                                                    Storyboard.TargetProperty="Opacity"
                                                    Storyboard.TargetName="FocusVisualBlack" />
                                            </Storyboard>
                                        </VisualState>
                                        <VisualState
                                            x:Name="Unfocused" />
                                        <VisualState
                                            x:Name="PointerFocused" />
                                    </VisualStateGroup>
                                </VisualStateManager.VisualStateGroups>
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition
                                            Width="15" />
                                        <ColumnDefinition
                                            Width="*" />
                                    </Grid.ColumnDefinitions>
                                    <Grid
                                        VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                                        <Grid
                                            x:Name="Root"
                                            HorizontalAlignment="Right"
                                            Margin="2 2 5 2">
                                            <Path
                                                x:Name="UncheckedVisual"
                                                Width="6"
                                                Height="9"
                                                Fill="#FFFFFFFF"
                                                VerticalAlignment="Center"
                                                HorizontalAlignment="Right"
                                                Data="M 0,0 L 0,9 L 5,4.5 Z"
                                                StrokeThickness="1"
                                                StrokeLineJoin="Miter">
                                                <Path.Stroke>
                                                    <SolidColorBrush
                                                        Color="#FF989898" />
                                                </Path.Stroke>
                                            </Path>
                                            <Path
                                                x:Name="CheckedVisual"
                                                Opacity="0"
                                                Width="6"
                                                Height="6"
                                                Fill="#FF262626"
                                                VerticalAlignment="Center"
                                                HorizontalAlignment="Center"
                                                Data="M 6,0 L 6,6 L 0,6 Z"
                                                StrokeLineJoin="Miter" />
                                        </Grid>
                                        <Rectangle
                                            x:Name="FocusVisualWhite"
                                            Height="15"
                                            Opacity="0"
                                            StrokeDashOffset="0.5"
                                            StrokeEndLineCap="Square"
                                            Stroke="{StaticResource FocusVisualWhiteStrokeThemeBrush}"
                                            StrokeDashArray="1,1"
                                            Width="15" />
                                        <Rectangle
                                            x:Name="FocusVisualBlack"
                                            Height="15"
                                            Opacity="0"
                                            StrokeDashOffset="1.5"
                                            StrokeEndLineCap="Square"
                                            Stroke="{StaticResource FocusVisualBlackStrokeThemeBrush}"
                                            StrokeDashArray="1,1"
                                            Width="15" />
                                    </Grid>
                                    <ContentPresenter
                                        x:Name="ContentPresenter"
                                        ContentTemplate="{TemplateBinding ContentTemplate}"
                                        ContentTransitions="{TemplateBinding ContentTransitions}"
                                        Content="{TemplateBinding Content}"
                                        Grid.Column="1"
                                        HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                        Margin="{TemplateBinding Padding}"
                                        VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                                    <Line
                                        Grid.ColumnSpan="2"
                                        HorizontalAlignment="Stretch"
                                        VerticalAlignment="Bottom"
                                        Height="1"
                                        StrokeThickness="1"
                                        X1="0"
                                        X2="1"
                                        Opacity="0.5"
                                        Stretch="Fill"
                                        Stroke="{StaticResource CheckBoxContentForegroundThemeBrush}" />
                                </Grid>
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <local:PropertyTemplateSelector
                x:Key="PropertyTemplateSelector">
                <DataTemplate
                    x:Key="Property">
                    <StackPanel
                        Orientation="Horizontal">
                        <TextBlock
                            Text="{Binding Name}"
                            FontWeight="Bold"
                            Margin="0,0,10,0"
                            xmlns:Interactivity="using:WinRTXamlToolkit.Interactivity"
                            xmlns:Behaviors="using:WinRTXamlToolkit.Controls.Behaviors">
                            <Interactivity:Interaction.Behaviors>
                                <Behaviors:HighlightBehavior
                                    x:Name="highlightBehavior"
                                    SearchString="{Binding ElementModel.TreeModel.PropertyNameFilter}" />
                                    <!--HighlightBrush="Aqua" />-->
                            </Interactivity:Interaction.Behaviors>
                        </TextBlock>
                        <TextBlock
                            Text="{Binding ValueString}"
                            Opacity="{Binding IsReadOnly, Converter={StaticResource BooleanToDoubleConverter}}" />
                    </StackPanel>
                </DataTemplate>
                <DataTemplate
                    x:Key="Group">
                    <Border
                        Background="Transparent"
                        PointerPressed="Border_PointerPressed"
                        HorizontalAlignment="Stretch">
                        <CheckBox
                            Style="{StaticResource ExpanderCheckBoxStyle}"
                            Content="{Binding Category}"
                            IsChecked="{Binding IsExpanded, Mode=TwoWay}" />
                    </Border>
                </DataTemplate>
            </local:PropertyTemplateSelector>
            
            <!-- EditablePropertyTemplateSelector -->
            <local:EditablePropertyTemplateSelector
                x:Key="EditablePropertyTemplateSelector">
                <DataTemplate
                    x:Key="Group">
                    <Border
                        Background="Transparent"
                        PointerPressed="Border_PointerPressed"
                        HorizontalAlignment="Stretch">
                        <CheckBox
                            Style="{StaticResource ExpanderCheckBoxStyle}"
                            Content="{Binding Category}"
                            IsChecked="{Binding IsExpanded, Mode=TwoWay}" />
                    </Border>
                </DataTemplate>
                <DataTemplate
                    x:Key="ImageSourcePropertyEditor">
                    <propertyEditors:ImageSourcePropertyEditor
                        Model="{Binding}" />
                </DataTemplate>
                <DataTemplate
                    x:Key="DefaultPropertyEditor">
                    <propertyEditors:DefaultPropertyEditor />
                </DataTemplate>
                <DataTemplate
                    x:Key="EnumPropertyEditor">
                    <propertyEditors:EnumPropertyEditor
                        EnumType="{Binding PropertyType}"
                        Model="{Binding}"
                        Value="{Binding Value}" />
                </DataTemplate>
                <DataTemplate
                    x:Key="FontWeightPropertyEditor">
                    <propertyEditors:FontWeightPropertyEditor />
                </DataTemplate>
                <DataTemplate
                    x:Key="StringPropertyEditor">
                    <propertyEditors:StringPropertyEditor />
                </DataTemplate>
                <DataTemplate
                    x:Key="NumericPropertyEditor">
                    <propertyEditors:NumericPropertyEditor
                        NumericType="{Binding PropertyType}"
                        Model="{Binding}" />
                </DataTemplate>
                <DataTemplate
                    x:Key="BrushPropertyEditor">
                    <propertyEditors:BrushPropertyEditor
                        Model="{Binding}" />
                </DataTemplate>
                <DataTemplate
                    x:Key="BooleanPropertyEditor">
                    <propertyEditors:BooleanPropertyEditor />
                </DataTemplate>
                <DataTemplate
                    x:Key="CacheModePropertyEditor">
                    <propertyEditors:CacheModePropertyEditor />
                </DataTemplate>
                <DataTemplate
                    x:Key="ThicknessPropertyEditor">
                    <propertyEditors:ThicknessPropertyEditor
                        Model="{Binding}"
                        Value="{Binding Value}" />
                </DataTemplate>
                <DataTemplate
                    x:Key="CornerRadiusPropertyEditor">
                    <propertyEditors:CornerRadiusPropertyEditor
                        Model="{Binding}"
                        Value="{Binding Value}" />
                </DataTemplate>
                <DataTemplate
                    x:Key="DependencyObjectPropertyEditor">
                    <propertyEditors:DependencyObjectPropertyEditor />
                </DataTemplate>
            </local:EditablePropertyTemplateSelector>
        </ResourceDictionary>
    </UserControl.Resources>    
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition
                Height="Auto" />
            <RowDefinition />
            <RowDefinition
                Height="Auto" />
        </Grid.RowDefinitions>
        <wrtxtc:WatermarkTextBox
            x:Name="SearchBox"
            WatermarkText="Search..."
            wrtxtce:TextBoxFocusExtensions.DisableSearchPaneOnFocus="true"
            wrtxtce:TextBoxFocusExtensions.AutoSelectOnFocus="true"
            TextChanged="OnSearchBoxTextChanged"/>
        <wrtxtd:EditableListBox
            Grid.Row="1"
            ItemsSource="{Binding Properties}"
            ItemTemplateSelector="{StaticResource PropertyTemplateSelector}"
            EditableItemTemplateSelector="{StaticResource EditablePropertyTemplateSelector}" />
        <StackPanel
            Grid.Row="2"
            Orientation="Horizontal">
            <Button
                x:Name="RefreshButton"
                Content="Refresh"
                Style="{StaticResource WrtxtdTextButtonStyleSmall}"
                Command="{Binding RefreshCommand}"
                FontSize="11"
                VerticalAlignment="Top"
                Margin="1,3,10,0"
                FontWeight="Normal" />
            <CheckBox
                Content="Show Unchanged"
                IsChecked="{Binding ShowDefaultedProperties, Mode=TwoWay}"
                FontSize="11" />
            <CheckBox
                Content="Show Read-Only"
                IsChecked="{Binding ShowReadOnlyProperties, Mode=TwoWay}"
                FontSize="11"
                Margin="10,0,10,0" />
            <ComboBox
                ItemsSource="{Binding PropertyLists}"
                DisplayMemberPath="Name"
                SelectedItem="{Binding CurrentPropertyList, Mode=TwoWay}"/>
            <CheckBox
                Content="Group"
                IsChecked="{Binding ShowPropertiesGrouped, Mode=TwoWay}"
                FontSize="11"
                Margin="10,0,0,0" />
        </StackPanel>
    </Grid>
</UserControl>
